﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;

namespace DefCore.Interfaces
{
    public interface IAssignable<T>
    {
        void CreateSaveFrom(T obj);
        void CreateFromLoad(T obj);
    }


    public static class IOHandle
    {
        public static T LoadFrom<T>(string filename)
        {
            using (FileStream fs = File.OpenRead(string.Format(@"{0}\data\{1}", Objects.GameObject.Content.RootDirectory, filename)))
            {
                BinaryFormatter binFormat = new BinaryFormatter();
                return (T)binFormat.Deserialize(fs);
            }
        }
        public static void Save<T>(string filename, T graph)
        {
            using (FileStream fs = File.Create(string.Format(@"{0}\data\{1}", Objects.GameObject.Content.RootDirectory, filename)))
            {
                BinaryFormatter binFormat = new BinaryFormatter();
                binFormat.Serialize(fs, graph);
            }
        }
    }
}
